#include <bits/stdc++.h>
using namespace std;

#define int long long

const int maxn = 1111111;
int n,a[maxn],median_a;
//a数组 只用来存纵坐标

int solve(int l, int r){
	//直接做就可以啊，，，为什么要用分治呢
	if ( l>r )
		return 0;
	if ( l==r )
		return abs( a[l] - median_a );
	
	int mid = (l+r)/2;
	return solve(l,mid) + solve(mid+1,r);
} 

signed main(){
	cin >> n;
	for ( int i=1; i<=n; i++ ){
		int xx,yy; cin >> xx >> yy;
		a[i] = yy;
	}
	
	sort(a+1, a+1+n);
	if (n%2==0)
		median_a = (a[n/2]+a[n/2+1]) / 2;
	else 
		median_a = (a[n/2]);
	
	cout << solve(1,n);
}
